<template>
  <div class="app-container">
    <div class="head-container">
      <div>
        <!-- 搜索 -->
        <!-- <el-input
            v-model="query.blurry"
            clearable
            size="small"
            placeholder="请输入关键词"
            style="width: 200px;"
            class="filter-item"
            @keyup.enter.native="crud.toQuery"
          /> -->
        <date-range-picker v-model="query.settlementDate" class="date-item" />
        <!-- <el-select
                v-model="query.enabled"
                clearable
                size="small"
                placeholder="状态"
                class="filter-item"
                style="width: 90px"
                @change="crud.toQuery"
              >
                <el-option
                  v-for="item in enabledTypeOptions"
                  :key="item.key"
                  :label="item.display_name"
                  :value="item.key"
                />
              </el-select> -->
        <rrOperation />
      </div>
      <div class="btnContain">
        <el-button @click="dialog = true">上传任务列表</el-button>
        <el-button @click="crud.doExport">下载任务列表</el-button>
      </div>
    </div>
    <!--表格渲染-->
    <el-table ref="table" v-loading="crud.loading" :height="height" border :data="crud.data" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
      <el-table-column :show-overflow-tooltip="true" prop="settlementDate" label="日期" />
      <el-table-column :show-overflow-tooltip="true" prop="projectName" label="项目">
        <template slot-scope="scope">
          <div>
            {{ scope.row.projectName }}
          </div>
        </template>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" prop="keywords" label="关键词">
        <template slot-scope="scope">
          <div>
            {{ scope.row.feedbackWork.keywords }}
          </div>
        </template>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" prop="bookId" label="书籍ID">
        <template slot-scope="scope">
          <div>
            {{ scope.row.feedbackWork.bookId }}
          </div>
        </template>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" prop="bookName" label="书籍名称">
        <template slot-scope="scope">
          <div>
            {{ scope.row.feedbackWork.bookName }}
          </div>
        </template>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" prop="userId" label="用户ID">
        <template slot-scope="scope">
          <div>
            {{ scope.row.user.id }}
          </div>
        </template>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" prop="userId" label="手机号">
        <template slot-scope="scope">
          <div>
            {{ scope.row.user.phone }}
          </div>
        </template>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" prop="username" label="用户名">
        <template slot-scope="scope">
          <div>
            {{ scope.row.user.username }}
          </div>
        </template>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" prop="phone" label="邀请人">
        <template slot-scope="scope">
          <div>
            {{ scope.row.userInvitation? scope.row.userInvitation.invitationCode: '--' }}
          </div>
        </template>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" prop="settlementName" label="结算方式" />
      <el-table-column :show-overflow-tooltip="true" prop="settlementQuantity" label="结算价格" />
      <el-table-column :show-overflow-tooltip="true" label="结算金额" align="center" prop="personalIncome" />
      <el-table-column :show-overflow-tooltip="true" prop="platformIncome" label="平台收益" />
    </el-table>
    <pagination />
    <el-dialog :visible.sync="dialog" title="上传文件" :close-on-click-modal="false" append-to-body width="500px" @close="doSubmit">
      <el-upload
        :before-remove="handleBeforeRemove"
        :on-success="handleSuccess"
        :on-error="handleError"
        :limit="1"
        :file-list="fileList"
        :headers="headers"
        :action="baseApi+'/api/earningsDetail/import'"
      >
        <el-button size="small" type="primary">点击上传</el-button>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="doSubmit">确认</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import crudGoodsDetail from '@/api/goodsDetail'
import CRUD, { presenter, header, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import pagination from '@crud/Pagination'
import { getToken } from '@/utils/auth'
import DateRangePicker from '@/components/DateRangePicker'
import { mapGetters } from 'vuex'
export default {
  name: 'GoodsDataDetail',
  components: { rrOperation, pagination, DateRangePicker },
  cruds() {
    return CRUD({ title: '数据明细', url: 'api/earningsDetail', crudMethod: { ...crudGoodsDetail }})
  },
  mixins: [presenter(), header(), crud()],
  data() {
    return {
      height: document.documentElement.clientHeight - 180 + 'px;',
      title: '文件', dialog: false, fileList: [], files: [],
      headers: { 'Authorization': getToken() }
    }
  },
  computed: {
    ...mapGetters([
      'baseApi'
    ])
  },
  created() {
  },
  mounted: function() {
    const that = this
    window.onresize = function temp() {
      that.height = document.documentElement.clientHeight - 180 + 'px;'
    }
  },
  methods: {
    doSubmit() {
      this.fileList = []
      this.dialog = false
      this.crud.toQuery()
    },
    handleBeforeRemove(file, fileList) {
      for (let i = 0; i < this.files.length; i++) {
        if (this.files[i].uid === file.uid) {
          crudGoods.del([this.files[i].id]).then(res => {})
          return true
        }
      }
    },
    handleSuccess(response, file, fileList) {
      const uid = file.uid
      const id = response.id
      this.files.push({ uid, id })
    },
    handleError(e, file, fileList) {
      const msg = JSON.parse(e.message)
      this.crud.notify(msg.message, CRUD.NOTIFICATION_TYPE.ERROR)
    }
  }
}
</script>

          <style rel="stylesheet/scss" lang="scss" scoped>
            .head-container {
              display: flex;
              justify-content: space-between;
              .btnContain {
                ::v-deep .el-button {
                background-color: rgba(236, 91, 91, 1);
                color: #fff;
                border: 0;
              }
              }
            }

          </style>

